package com.itheima.day15.TCP.test3;

import java.io.*;
import java.net.Socket;


// 客户端
public class ClientDemo {
    public static void main(String[] args) throws IOException {
        // 1.创建Socket对象
        Socket s = new Socket("10.254.1.79", 10004);

        // 2.获取输出对象，发送数据，并关闭输出流
        System.out.println(1);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
        bw.write("你好");
        bw.newLine();
        bw.flush();
        s.shutdownOutput();

        // 3.接收响应
        System.out.println(4);
        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        String str;
        while ((str = br.readLine()) != null) {
            System.out.println(str);
        }


        s.close();


    }
}
